home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 19.6 KB | 620 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWPresen.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFrameW.hpp"
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- #ifndef FWPART_H
- #include "FWPart.h"
- #endif
-
- #ifndef FWFRAME_H
- #include "FWFrame.h"
- #endif
-
- #ifndef FWSELECT_H
- #include "FWSelect.h"
- #endif
-
- #ifndef FWITERS_H
- #include "FWIters.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWVIEWAS_H
- #include "FWViewAs.h"
- #endif
-
- #ifndef FWEXCEPT_H
- #include "FWExcept.h"
- #endif
-
- #ifndef FWSESION_H
- #include "FWSesion.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWODGEOM_H
- #include "FWODGeom.h"
- #endif
-
- #ifndef FWWINDOW_H
- #include "FWWindow.h"
- #endif
-
- // ----- Foundation Includes -----
-
- #ifndef FWBNDSTR_H
- #include "FWBndStr.h"
- #endif
-
- #ifndef FWSOMENV_H
- #include "FWSOMEnv.h"
- #endif
-
- // ----- OpenDoc Includes -----
- #ifndef SOM_ODFacet_xh
- #include <Facet.xh>
- #endif
-
- #ifndef SOM_ODFocusSet_xh
- #include <FocusSet.xh>
- #endif
-
- #ifndef SOM_ODShape_xh
- #include <Shape.xh>
- #endif
-
- #ifndef SOM_ODFrame_xh
- #include <Frame.xh>
- #endif
-
- #ifndef SOM_ODArbitrator_xh
- #include <Arbitrat.xh>
- #endif
-
- //========================================================================================
- // RunTime Info
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwpart2
- #endif
-
- //========================================================================================
- // Template Instantiations
- //========================================================================================
-
- FW_DEFINE_AUTO_TEMPLATE(FW_TOrderedCollectionIterator, FW_CPresentation)
- FW_DEFINE_AUTO_TEMPLATE(FW_TOrderedCollection, FW_CPresentation)
- FW_DEFINE_AUTO_TEMPLATE(FW_TOrderedCollectionIterator, FW_CPrivDisplayFrame)
- FW_DEFINE_AUTO_TEMPLATE(FW_TOrderedCollection, FW_CPrivDisplayFrame)
-
- #ifdef FW_USE_TEMPLATE_PRAGMAS
-
- #pragma template_access public
- #pragma template FW_TOrderedCollection<FW_CPresentation>
- #pragma template FW_TOrderedCollectionIterator<FW_CPresentation>
- #pragma template FW_TOrderedCollection<FW_CPrivDisplayFrame>
- #pragma template FW_TOrderedCollectionIterator<FW_CPrivDisplayFrame>
-
- #endif
-
- //========================================================================================
- // class FW_CPrivDisplayFrame
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivDisplayFrame::FW_CPrivDisplayFrame
- //----------------------------------------------------------------------------------------
-
- FW_CPrivDisplayFrame::FW_CPrivDisplayFrame(Environment *ev, FW_CFrame* frame) :
- fFrameID(frame->GetID(ev)),
- fODFrame(frame->GetODFrame(ev)),
- fFrame(frame)
- {
- fODFrame->Acquire(ev);
- fODFrame->SetPartInfo(ev, (ODInfoType)frame);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivDisplayFrame::FW_CPrivDisplayFrame
- //----------------------------------------------------------------------------------------
-
- FW_CPrivDisplayFrame::FW_CPrivDisplayFrame(Environment *ev, ODID frameID) :
- fFrameID(frameID),
- fODFrame(NULL),
- fFrame(NULL)
- {
- FW_UNUSED(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivDisplayFrame::~FW_CPrivDisplayFrame
- //----------------------------------------------------------------------------------------
-
- FW_CPrivDisplayFrame::~FW_CPrivDisplayFrame()
- {
- FW_SOMEnvironment ev;
- Release(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivDisplayFrame::Release
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivDisplayFrame::Release(Environment *ev)
- {
- if (fODFrame)
- {
- fODFrame->SetPartInfo(ev, NULL);
- fODFrame->Release(ev);
- fODFrame = NULL;
- }
- }
-
- //========================================================================================
- // class FW_CPresentation
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CPresentation::FW_CPresentation
- //----------------------------------------------------------------------------------------
-
- FW_CPresentation::FW_CPresentation(Environment *ev,
- FW_CPart* thePart,
- FW_CSelection* selection,
- ODTypeToken presentationType,
- FW_ResourceID viewResourceID,
- FW_ResourceID rootViewResourceID) :
- fPart(thePart),
- fFrames(NULL),
- fSelection(selection),
- fPresentationType(presentationType),
- fFocusSet(NULL),
- fViewAsThumbnail(NULL),
- fViewAsSmallIcon(NULL),
- fViewAsLargeIcon(NULL),
- fDefaultEmbeddedFrameViewType(FW_CPart::fgViewAsFrameToken),
- fDragPending(FALSE),
- fViewResourceID(viewResourceID),
- fRootViewResourceID(rootViewResourceID)
- {
- FW_ASSERT(thePart);
-
- fFrames = FW_NEW(FW_TOrderedCollection<FW_CPrivDisplayFrame>, ());
-
- // ----- By default add all common foci to the presentation
- // (floating windows & dialogs will updated later)
- fFocusSet = FW_CSession::GetArbitrator(ev)->CreateFocusSet(ev);
- fFocusSet->Add(ev, FW_CPart::fgKeyFocusToken);
- fFocusSet->Add(ev, FW_CPart::fgMenuFocusToken);
- fFocusSet->Add(ev, FW_CPart::fgSelectionFocusToken);
- fFocusSet->Add(ev, FW_CPart::fgClipboardFocusToken);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPresentation::~FW_CPresentation
- //----------------------------------------------------------------------------------------
-
- FW_CPresentation::~FW_CPresentation()
- {
- FW_ASSERT(fViewAsThumbnail == NULL); // Should already have been released
- FW_ASSERT(fViewAsSmallIcon == NULL); // Should already have been released
- FW_ASSERT(fViewAsLargeIcon == NULL); // Should already have been released
-
- delete fSelection;
-
- FW_SOMEnvironment ev;
-
- if (fFrames != NULL)
- {
- FW_CPrivDisplayFrame* displayFrame;
- while ((displayFrame = fFrames->First()) != NULL)
- PrivDeleteDisplayFrame(ev, displayFrame);
-
- delete fFrames;
- }
-
- delete fFocusSet;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPresentation::Invalidate
- //----------------------------------------------------------------------------------------
- // invalidShape should be in content coordinates
-
- void FW_CPresentation::Invalidate(Environment *ev, ODShape* invalidShape, ODID sequenceNumber)
- {
- FW_CPresentationFrameIterator ite(ev, this);
- for (FW_CFrame* frame = ite.First(ev); ite.IsNotComplete(ev); frame = ite.Next(ev))
- {
- if (sequenceNumber == 0 || sequenceNumber == frame->GetSequenceNumber(ev))
- {
- FW_CAcquiredODShape aqInvalidShape;
- if (invalidShape != NULL)
- {
- FW_CAcquiredODTransform aqInternalTransform = frame->AcquireInternalTransform(ev, NULL);
- aqInvalidShape = invalidShape->Copy(ev);
- aqInvalidShape->Transform(ev, aqInternalTransform);
- }
-
- frame->GetODFrame(ev)->Invalidate(ev, aqInvalidShape, NULL); // if aqInvalidShape is NULL OpenDoc will use the aggregate
- // clip shape
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPresentation::Validate
- //----------------------------------------------------------------------------------------
- // validShape should be in content coordinates
-
- void FW_CPresentation::Validate(Environment *ev, ODShape* validShape, ODID sequenceNumber)
- {
- FW_CPresentationFrameIterator ite(ev, this);
- for (FW_CFrame* frame = ite.First(ev); ite.IsNotComplete(ev); frame = ite.Next(ev))
- {
- if (sequenceNumber == 0 || sequenceNumber == frame->GetSequenceNumber(ev))
- {
- FW_CAcquiredODShape aqValidShape;
- if (validShape != NULL)
- {
- FW_CAcquiredODTransform aqInternalTransform = frame->AcquireInternalTransform(ev, NULL);
- aqValidShape = validShape->Copy(ev);
- aqValidShape->Transform(ev, aqInternalTransform);
- }
-
- frame->GetODFrame(ev)->Validate(ev, aqValidShape, NULL); // if aqInvalidShape is NULL OpenDoc will use the aggregate
- // clip shape
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPresentation::Invalidate
- //----------------------------------------------------------------------------------------
- // invalidRect should be in content coordinates
-
- void FW_CPresentation::Invalidate(Environment* ev, const FW_CRect& invalidRect, ODID sequenceNumber)
- {
- FW_CAcquiredODShape aqShape = ::FW_NewODShape(ev, invalidRect);
- Invalidate(ev, aqShape, sequenceNumber);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPresentation::Validate
- //----------------------------------------------------------------------------------------
- // validRect should be in content coordinates
-
- void FW_CPresentation::Validate(Environment* ev, const FW_CRect& validRect, ODID sequenceNumber)
- {
- FW_CAcquiredODShape aqShape = ::FW_NewODShape(ev, validRect);
- Validate(ev, aqShape, sequenceNumber);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPresentation::ContentUpdated
- //------------------------------------------------------------------------
-
- void FW_CPresentation::ContentUpdated(Environment* ev, ODUpdateID updateID)
- {
- // When ContentUpdated is called because of updating a link, a change ID is supplied.
- // Otherwise, we need to create a unique change ID -
- if (updateID == kODUnknownUpdate)
- updateID = FW_CSession::UniqueUpdateID(ev);
-
- FW_CPresentationFrameIterator ite(ev, this);
- for (FW_CFrame* frame = ite.First(ev); ite.IsNotComplete(ev); frame = ite.Next(ev))
- {
- frame->GetODFrame(ev)->ContentUpdated(ev, updateID);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPresentation::PrivAddFrame
- //----------------------------------------------------------------------------------------
-
- void FW_CPresentation::PrivAddFrame(Environment *ev, FW_CFrame* frame)
- {
- fFrames->AddLast(new FW_CPrivDisplayFrame(ev, frame));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPresentation::PrivGetDisplayFrame
- //----------------------------------------------------------------------------------------
-
- FW_CPrivDisplayFrame* FW_CPresentation::PrivGetDisplayFrame(FW_CFrame* frame) const
- {
- FW_TOrderedCollectionIterator<FW_CPrivDisplayFrame> ite(fFrames);
- for (FW_CPrivDisplayFrame* displayFrame = ite.First(); ite.IsNotComplete(); displayFrame = ite.Next())
- {
- if (displayFrame->fFrame == frame)
- return displayFrame;
- }
-
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPresentation::PrivDeleteDisplayFrame
- //----------------------------------------------------------------------------------------
-
- void FW_CPresentation::PrivDeleteDisplayFrame(Environment *ev, FW_CPrivDisplayFrame* displayFrame)
- {
- FW_UNUSED(ev);
-
- // ----- First Remove it from the list -----
- fFrames->Remove(displayFrame);
-
- // ----- Now I can delete it
- delete displayFrame;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPresentation::ChangeAllFramesPresentation
- //----------------------------------------------------------------------------------------
-
- void FW_CPresentation::ChangeAllFramesPresentation(Environment *ev, FW_CPresentation* newPresentation) const
- {
- if (this == newPresentation)
- return;
-
- FW_CPrivDisplayFrame* displayFrame = fFrames->First();
- while (displayFrame != NULL)
- {
- FW_CFrame* theFrame = displayFrame->fFrame;
- if (theFrame != NULL)
- theFrame->ChangePresentation(ev, newPresentation);
-
- displayFrame = fFrames->First();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPresentation::ReleaseAll
- //----------------------------------------------------------------------------------------
-
- void FW_CPresentation::ReleaseAll(Environment *ev)
- {
- FW_TOrderedCollectionIterator<FW_CPrivDisplayFrame> ite(fFrames);
- for (FW_CPrivDisplayFrame* displayFrame = ite.First(); ite.IsNotComplete(); displayFrame = ite.Next())
- {
- displayFrame->Release(ev);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPresentation::PrivRemoveFrame
- //----------------------------------------------------------------------------------------
- // Used in ChangePresentation
-
- void FW_CPresentation::PrivRemoveFrame(Environment *ev, FW_CFrame* frame)
- {
- FW_UNUSED(ev);
-
- // ----- Remove it from the list -----
- FW_CPrivDisplayFrame* displayFrame = PrivGetDisplayFrame(frame);
- FW_ASSERT(displayFrame);
-
- PrivDeleteDisplayFrame(ev, displayFrame);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPresentation::PrivFrameRemoved
- //----------------------------------------------------------------------------------------
-
- void FW_CPresentation::PrivFrameRemoved(Environment *ev, FW_CFrame* frame, FW_Boolean toStorage)
- {
- FW_Boolean wasLastActive = (fPart->GetLastActiveFrame(ev) == frame);
-
- // ----- Notify the frame -----
- frame->FrameRemoved(ev, toStorage);
-
- // ----- Remove it from the list -----
- FW_CPrivDisplayFrame* displayFrame = PrivGetDisplayFrame(frame);
- FW_ASSERT(displayFrame);
-
- PrivDeleteDisplayFrame(ev, displayFrame);
-
- // ----- delete it if not shared -----
- if (!frame->PrivInSharedWindow(ev))
- delete frame;
-
- // ----- Set the last active frame to the first frame of this presentation -----
- if (wasLastActive)
- {
- FW_CPrivDisplayFrame* displayFrame = fFrames->First();
- fPart->PrivSetLastActiveFrame(displayFrame ? displayFrame->fFrame : NULL);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPresentation::CountFrame
- //----------------------------------------------------------------------------------------
-
- unsigned long FW_CPresentation::CountFrame(Environment *ev) const
- {
- FW_UNUSED(ev);
- return fFrames->Count();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPresentation::RemoveSiblingFrame
- //----------------------------------------------------------------------------------------
-
- void FW_CPresentation::RemoveSiblingFrame(Environment* ev, FW_CFrame* frameToRemove)
- {
- FW_ASSERT(frameToRemove->IsRequestedFrame(ev)); // Cannot remove a frame not requested
-
- FW_CAcquiredODFrame embeddingFrame = frameToRemove->AcquireContainingFrame(ev);
- FW_CAcquiredODPart embeddingPart = embeddingFrame->AcquirePart(ev);
-
- embeddingPart->RemoveEmbeddedFrame(ev, frameToRemove->GetODFrame(ev));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPresentation::RequestSiblingFrame
- //----------------------------------------------------------------------------------------
- // returns kODNULLID if the request was not fulfilled
-
- ODID FW_CPresentation::RequestSiblingFrame(Environment* ev,
- FW_CFrame* baseFrame,
- ODShape* suggestedFrameShape,
- ODTypeToken viewType,
- FW_Boolean isOverlaid)
- {
- FW_CAcquiredODFrame embeddingFrame = baseFrame->AcquireContainingFrame(ev);
- FW_CAcquiredODPart embeddingPart = embeddingFrame->AcquirePart(ev);
-
- FW_CAcquiredODShape frameShape = suggestedFrameShape->Copy(ev);
- FW_CAcquiredODFrame newFrame = embeddingPart->RequestEmbeddedFrame(ev,
- embeddingFrame,
- baseFrame->GetODFrame(ev),
- frameShape,
- fPart->GetODPart(ev),
- viewType,
- fPresentationType,
- isOverlaid);
- ODID newSequence = kODNULLID;
-
- if (newFrame != NULL)
- {
- FW_CFrame* fwFrame = FW_CFrame::ODtoFWFrame(ev, newFrame);
-
- ODID newFrameGroup = fwFrame->GetFrameGroup(ev);
- newSequence = fwFrame->GetSequenceNumber(ev);
-
- // ----- Set the RequestedFrame flag -----
- FW_CPresentationFrameIterator ite(ev, this, newFrameGroup, newSequence);
- for (FW_CFrame* aFrame = ite.First(ev); ite.IsNotComplete(ev); aFrame = ite.Next(ev))
- {
- aFrame->PrivSetRequestedFrame(ev);
- }
- }
-
- return newSequence;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPresentation::PrivAcquireViewAs
- //----------------------------------------------------------------------------------------
-
- FW_CViewAs* FW_CPresentation::PrivAcquireViewAs(Environment* ev, FW_CFrame* frame, ODTypeToken viewAsToken)
- {
- FW_ASSERT(viewAsToken == FW_CPart::fgViewAsThumbnailToken ||
- viewAsToken == FW_CPart::fgViewAsSmallIconToken ||
- viewAsToken == FW_CPart::fgViewAsLargeIconToken);
-
- FW_CViewAs** viewAsPtr = NULL;
-
- if (viewAsToken == FW_CPart::fgViewAsThumbnailToken)
- viewAsPtr = &fViewAsThumbnail;
- else if (viewAsToken == FW_CPart::fgViewAsSmallIconToken)
- viewAsPtr = &fViewAsSmallIcon;
- else
- viewAsPtr = &fViewAsLargeIcon;
-
- if ((*viewAsPtr) != NULL)
- (*viewAsPtr)->Acquire();
- else
- (*viewAsPtr) = frame->NewViewAs(ev, viewAsToken);
-
- (*viewAsPtr)->Load(ev, frame);
-
- return (*viewAsPtr);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPresentation::PrivReleaseViewAs
- //----------------------------------------------------------------------------------------
-
- void FW_CPresentation::PrivReleaseViewAs(FW_CViewAs* viewAs)
- {
- FW_ASSERT(viewAs == fViewAsThumbnail || viewAs == fViewAsSmallIcon || viewAs == fViewAsLargeIcon);
-
- if (viewAs->Release() == 0)
- {
- if (viewAs == fViewAsThumbnail)
- fViewAsThumbnail = NULL;
- else if (viewAs == fViewAsSmallIcon)
- fViewAsSmallIcon = NULL;
- else
- fViewAsLargeIcon = NULL;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPresentation::UpdateViewAs
- //----------------------------------------------------------------------------------------
-
- void FW_CPresentation::UpdateViewAs(Environment* ev)
- {
- if (fViewAsThumbnail != NULL)
- fViewAsThumbnail->Unload(ev);
-
- if (fViewAsSmallIcon != NULL)
- fViewAsSmallIcon->Unload(ev);
-
- if (fViewAsLargeIcon != NULL)
- fViewAsSmallIcon->Unload(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPresentation::AdoptFocusSet
- //----------------------------------------------------------------------------------------
- // Pass NULL to create an empty focus Set
-
- void FW_CPresentation::AdoptFocusSet(Environment* ev, ODFocusSet* newFocusSet)
- {
- #ifdef FW_DEBUG
- // No frame should be active when changing the focus set because it is used
- // during activation/deactivation
- FW_CPresentationFrameIterator ite(ev, this);
- for (FW_CFrame* aFrame = ite.First(ev); ite.IsNotComplete(ev); aFrame = ite.Next(ev))
- {
- FW_ASSERT(aFrame->HasSelectionFocus(ev) == FALSE);
- }
- #endif
-
- // ----- Test first that we are not reassigning the same one -----
- if (newFocusSet != fFocusSet)
- {
- delete fFocusSet;
- fFocusSet = NULL;
- }
-
- if (newFocusSet)
- fFocusSet = newFocusSet;
- else
- fFocusSet = FW_CSession::GetArbitrator(ev)->CreateFocusSet(ev); // Empty focus set
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPresentation::PrivNewFrame
- //----------------------------------------------------------------------------------------
- // PrivNewFrame is used internaly for example by the about dialog. Part should never
- // have to subclass FW_CPresentation. Use FW_CPart::NewFrame instead.
-
- FW_CFrame* FW_CPresentation::PrivNewFrame(Environment *ev,
- ODFrame* odFrame,
- FW_Boolean fromStorage)
- {
- FW_UNUSED(ev);
- FW_UNUSED(odFrame);
- FW_UNUSED(fromStorage);
- return NULL;
- }